<template>
  <div class="system_integration_Frequencydetail">
    <c-title :hide="false" :text="'次数明细'" />
    <div class="list" v-for="(item, index) in list" :key="index">
      <div class="lis_l">
        <div class="title">{{ item.source_name }}</div>
        <div class="timer">{{ item.created_at }}</div>
      </div>
      <div class="lis_r">
        <div class="lis_r_t">{{ item.change_amount }}</div>
        <div class="lis_r_b" v-if="item.has_one_order">{{ item.has_one_order.order_sn }}</div>
        <div class="time_end" v-if="item.expire_at">{{ item.left_string }}</div>
      </div>
    </div>
    <van-empty v-if="list.length == 0" image="https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/bodyHealthCheck%2Freport.png" description="暂无检测报告" />
  </div>
</template>
<script>
import { scrollMixin } from "utils/mixin";
export default {
  mixins: [scrollMixin],
  data() {
    return {
      list: [],
      isLoadMore: true,
      page: 1,
      total_page: 0
    };
  },
  activated() {
    this.init();
    this.getData();
  },
  methods: {
    init() {
      this.page = 1;
      this.isLoadMore = true;
      this.total_page = 0;
    },
    async getData() {
      let { data, msg, result } = await $http.post("plugin.body-health-check.api.usage-detail.index", {}, "");
      if (result) {
        this.list = data.data;
        this.total_page = data.last_page;
        this.isLoadMore = true;
      } else {
        this.$toast(msg);
      }
    },
    async getMoreData() {
      if (!this.isLoadMore) return;
      this.isLoadMore = false; // 防止多次请求分页数据
      if (this.page >= this.total_page) {
        return;
      } else {
        this.page += 1;
        let json = {
          page: this.page
        };
        let { data, msg, result } = await $http.post("plugin.body-health-check.api.usage-detail.index", json, "");
        this.isLoadMore = true;
        if (result) {
          this.list = this.list.concat(data.data);
        } else {
          this.page = this.page - 1;
          this.isLoadMore = false;
          this.$toast(msg);
        }
      }
    }
  }
};
</script>
<style lang="scss" scoped>
.system_integration_report {
  min-height: 100vh;
}
.list {
  background: #ffffff;
  border-radius: 0.5rem;
  margin: 0.63rem 0.75rem 0 0.75rem;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 0.91rem 0.75rem;
  box-sizing: border-box;
  .lis_l {
    flex: 1;
    text-align: left;
    .title {
      font-weight: bold;
      font-size: 0.88rem;
      color: #00001c;
    }
    .timer {
      font-size: 0.81rem;
      color: #6e6e79;
      margin-top: 0.5rem;
    }
  }
  .lis_r {
    flex: 1;
    text-align: right;
    .lis_r_t {
      font-weight: bold;
      font-size: 0.88rem;
      color: #00001c;
    }

    .lis_r_b,
    .time_end {
      font-size: 0.81rem;
      color: #f15353;
      margin-top: 0.5rem;
    }
  }
}
</style>
